
enum MODE_LIST {
    //% block="连续模式：分辨率1 lux，耗时约120ms（默认）"
     CONTINUOUS_HIGH_RES_MODE,
    //% block="连续模式：分辨率0.5 lux，耗时约120ms"
     CONTINUOUS_HIGH_RES_MODE_2,
    //% block="连续模式：分辨率4 lux，耗时约16ms"
     CONTINUOUS_LOW_RES_MODE,
    //% block="单次模式：分辨率1 lux，耗时约120ms"
     ONE_TIME_HIGH_RES_MODE,
    //% block="单次模式：分辨率0.5 lux，耗时约120ms"
     ONE_TIME_HIGH_RES_MODE_2,
    //% block="单次模式：分辨率4 lux，耗时约16ms"
     ONE_TIME_LOW_RES_MODE
}





//% color="#5ba55b" iconWidth=50 iconHeight=40
namespace BH1750FVI_Sensor { 
    //% block="初始化数字光照传感器" blockType="command"
     export function begin(parameter: any, block: any) {
        Generator.addInclude('#include_Wire_h>', '#include <Wire.h>');
        Generator.addInclude('#include_RL_BH1750_h', '#include <RL_BH1750.h>');
        Generator.addObject(`BH1750_lightMeter`, `BH1750`, ` lightMeter;`);
		Generator.addSetup(`Wire_begin();`, `Wire.begin();`);
        Generator.addSetup(`lightMeter_begin`, `lightMeter.begin();`);
    }
    //% block="配置数字光照传感器[MODE]" blockType="command"
    //% MODE.shadow="dropdown" MODE.options="MODE_LIST" 
     export function configure(parameter: any, block: any) {
        let mode = parameter.MODE.code;
        Generator.addInclude('#include_Wire_h>', '#include <Wire.h>');
        Generator.addInclude('#include_RL_BH1750_h', '#include <RL_BH1750.h>');
        Generator.addObject(`BH1750_lightMeter`, `BH1750`, ` lightMeter;`);
        Generator.addSetup(`Wire_begin();`, `Wire.begin();`);
		Generator.addSetup(`lightMeter_begin`, `lightMeter.begin();`);
        Generator.addCode(`lightMeter.configure(BH1750::${mode});`);
    }
    //% block="设置数字光照传感器测量时间[TIME]" blockType="command"
    //% TIME.shadow="range"   TIME.params.min=32    TIME.params.max=254    TIME.defl=69
      export function setMTreg(parameter: any, block: any) {
        let time = parameter.TIME.code;
        Generator.addInclude('#include_Wire_h>', '#include <Wire.h>');
        Generator.addInclude('#include_RL_BH1750_h', '#include <RL_BH1750.h>');
        Generator.addObject(`BH1750_lightMeter`, `BH1750`, ` lightMeter;`);
        Generator.addSetup(`Wire_begin();`, `Wire.begin();`);
		Generator.addSetup(`lightMeter_begin`, `lightMeter.begin();`);
        Generator.addCode(`lightMeter.setMTreg(${time});`);
    }
     //% block="数字光照传感器测量完成？" blockType="boolean"
     export function measurementReady(parameter: any, block: any) {
        Generator.addInclude('#include_Wire_h>', '#include <Wire.h>');
        Generator.addInclude('#include_RL_BH1750_h', '#include <RL_BH1750.h>');
        Generator.addObject(`BH1750_lightMeter`, `BH1750`, ` lightMeter;`);
        Generator.addSetup(`Wire_begin();`, `Wire.begin();`);
		Generator.addSetup(`lightMeter_begin`, `lightMeter.begin();`);
        Generator.addCode(`lightMeter.measurementReady(true)`);
    }
    //% block="读取数字光照传感器" blockType="reporter"
     export function readLightLevel(parameter: any, block: any) {
        Generator.addInclude('#include_Wire_h>', '#include <Wire.h>');
        Generator.addInclude('#include_RL_BH1750_h', '#include <RL_BH1750.h>');
        Generator.addObject(`BH1750_lightMeter`, `BH1750`, ` lightMeter;`);
        Generator.addSetup(`Wire_begin();`, `Wire.begin();`);
		Generator.addSetup(`lightMeter_begin`, `lightMeter.begin();`);
        Generator.addCode(`lightMeter.readLightLevel()`);
    }

   
}
